package com.raleqing.text;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RContactAdapter extends BaseAdapter {

	public Context mContext;
	public ArrayList<Contact> result;

	public RContactAdapter(Context mContext, ArrayList<Contact> result) {
		super();
		this.mContext = mContext;
		this.result = result;
	}

	@Override
	public int getCount() {
		return result.size();
	}

	@Override
	public Object getItem(int position) {
		return result.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.allistview, null);
			holder = new Holder();
			holder.name = (TextView) convertView.findViewById(R.id.listname);
			holder.job = (TextView) convertView.findViewById(R.id.listjob);
			holder.dept = (TextView) convertView.findViewById(R.id.listdept);
			holder.bsector = (TextView) convertView
					.findViewById(R.id.listsubsector);
			convertView.setTag(holder);
		}
		holder = (Holder) convertView.getTag();
		Contact contact = result.get(position);
		System.out.println(contact.name);
		holder.name.setText(contact.name);
		holder.job.setText(contact.job);
		holder.dept.setText(contact.subDept);
		holder.bsector.setText(contact.subsector);
		return convertView;
	}

	static class Holder {
		TextView name;
		TextView job;
		TextView dept;
		TextView bsector;
	}
	
	
}
